package code.framework.android.view;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * 
 */
public class NavBarViewHandler {

	// private class Holder extends ViewHolderBase {
	private class Holder {
		public Button navPanelPreviousButton;
		public ViewGroup navPanelCenterLinearLayout;
		public TextView navPanelTitle;
		public Button navPanelNextButton;

		public Holder() {
			super();
			// super.absorb(Holder.class);
		}
	}

	private Class<?> rClass;

	private Holder holder;
	private Context context;

	public NavBarViewHandler() {
	}

	public NavBarViewHandler(Activity a) {
		register(a);
	}

	/**
	 * 
	 * @param a
	 */
	public void register(Activity a) {
		// HkmoviesActivityInfo previousActivityInfo = HkmoviesContext
		// .getInstance().peekActivityInfo();
		// HkmoviesContext.getInstance().pushActivity(a);
		// HkmoviesActivityInfo currentActivityInfo = HkmoviesContext
		// .getInstance().peekActivityInfo();
		// register(a,
		// HkmoviesResourceHelper.getLocaleString(currentActivityInfo
		// .getName(), a));
		// if (previousActivityInfo != null) {
		// this.registerPreviousAction(a, HkmoviesResourceHelper
		// .getLocaleString(previousActivityInfo.getShortName(), a));
		// }
		// if (MovieListActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_list", a));
		// }
		// if (MovieActivity.class.isAssignableFrom(a.getClass())) {
		// register(a, HkmoviesResourceHelper.getLocaleString("title_movie",
		// a));
		// }
		// if (MovieScreenShotActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_screen_shot",
		// a));
		// }
		// if (MovieCommentListActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_comment_list",
		// a));
		// }
		// if (MovieCommentRecentActivity.class.isAssignableFrom(a.getClass()))
		// {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_list", a));
		// }
		// if (MovieCommentAddActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_comment_list",
		// a));
		// }
		// if (MovieScheduleListActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_schedule", a));
		// }
		// if (MovieScheduleActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_movie_schedule", a));
		// }
		// if (CinemaListActivity.class.isAssignableFrom(a.getClass())) {
		// register(a,
		// HkmoviesResourceHelper.getLocaleString("title_cinema_list", a));
		// }
		// if (CinemaActivity.class.isAssignableFrom(a.getClass())) {
		// register(a, HkmoviesResourceHelper.getLocaleString("title_cinema",
		// a));
		// }
	}

	private void register(Activity a, String title) {
		// a.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		this.context = a.getApplicationContext();
		/*
		 * TODO: uncomment
		 */
		// a.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
		// R.layout.navbar);
		// inflate and add
		// final LayoutInflater layoutInflater = LayoutInflater.from(c);
		// viewGroup = (ViewGroup) layoutInflater.inflate(R.layout.navbar,
		// parent, false);
		holder = new Holder();
		// holder.absorb(viewGroup);
		// parent.addView(viewGroup, 0);
		/*
		 * TODO: uncomment
		 */
		// holder.absorb(a);
		// set content
		// holder.navPanelPreviousButton.setVisibility(View.GONE);
		// holder.navPanelNextButton.setVisibility(View.GONE);
		holder.navPanelTitle.setText(title);
	}

	private void registerPreviousAction(final Activity activity,
			final String label) {
		holder.navPanelPreviousButton.setVisibility(View.VISIBLE);
		holder.navPanelPreviousButton.setText(label);
		holder.navPanelPreviousButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				activity.finish();
			}
		});
	}

	public Button getPreviousButton() {
		return holder.navPanelPreviousButton;
	}

	public Button getNextButton() {
		return holder.navPanelNextButton;
	}

	public void clearCenterButton() {
		holder.navPanelCenterLinearLayout.removeAllViews();
	}

	public Button createCenterButton(String label) {
		holder.navPanelTitle.setVisibility(View.GONE);
		/*
		 * TODO: uncomment
		 */
		// Button button = (Button) LayoutInflater.from(context).inflate(
		// R.layout.navbar_button, null);
		// button.setText(label);
		Button button = null;
		holder.navPanelCenterLinearLayout.addView(button);
		return button;
	}

	// public void registerPageNavigation() {
	// Button previousButton = (Button)
	// super.findViewById(R.id.navPanelPreviousButton);
	// previousButton.setOnClickListener(new OnClickListener() {
	// public void onClick(View v) {
	// HkmoviesContextHelper.startIntent(HkmoviesActivityBase.this,
	// MovieListActivity.class);
	// }
	// });
	// previousButton.setText("");
	//    	
	// TextView title = (TextView) super.findViewById(R.id.navPanelTitle);
	// title.setText("Movie Information");
	//    	
	// Button nextButton = (Button) super.findViewById(R.id.navPanelNextButton);
	// nextButton.setOnClickListener(new OnClickListener() {
	// public void onClick(View v) {
	// // HkmoviesContextHelper.startIntent(HkmoviesActivityBase.this,
	// MovieScheduleListActivity.class);
	// }
	// });
	// }

}
